using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using WeddingDBTableAdapters;

public partial class RSVP : System.Web.UI.Page
{
	private const int _mMinRSVPNo = 1000;

    protected void Page_Load(object sender, EventArgs e)
    {
		 if (!IsPostBack)
		 {
			 SetFocus(txtName);
		 }
    }

	protected void btnCancel_Click(object sender, EventArgs e)
	{
		Response.Redirect("./");
	}

	protected void btnSave_Click(object sender, EventArgs e)
	{
		int? maxRSVPNo;
		int newRSVPNo = _mMinRSVPNo;
		RSVPTableAdapter rsvpAdapter = new RSVPTableAdapter();

		maxRSVPNo = rsvpAdapter.GetMaxReservationNo();

		//was there a maxRSVPNo?
		if (maxRSVPNo != null)
		{
			newRSVPNo = (int) maxRSVPNo;

			newRSVPNo++;
		}

		rsvpAdapter.Insert(newRSVPNo, txtName.Text, Int16.Parse(txtGuestCount.Text), 
			DateTime.Now);

		pnlInput.Visible = false;
		pnlConfirmation.Visible = true;
		lblGuestCount.Text = txtGuestCount.Text;
		lblName.Text = txtName.Text;
		lblReservationNo.Text = newRSVPNo.ToString();
	}
}
